package map;

import java.util.HashMap;
import java.util.Map;

/**
 * created by flyketch
 * 19-12-21 下午12:26
 */
public class MapTest {
    public static void main(String[] args) {
        Map<String, Object> map = new HashMap<String, Object>(){{
            put("name", "steve");
            put("age", 24);
            put("sex", "man");
            put("country", "china");
        }};

        // java 8 stream
        map.entrySet().stream().forEach( (entry) -> {
            System.out.println(entry.getKey() + ", " + entry.getValue());
        });

        System.out.println(map);

        // entrySet 遍历
        for (Map.Entry<String, Object> entry: map.entrySet()) {
            System.out.println(entry.getKey() + ", " + entry.getValue());
        }

        Map<String, Object> maps = new HashMap<>();
        maps.put("hello", "");
        maps.put("one", "one");
        if (maps != null) {
            System.out.println("not null");
        } else {
            System.out.println("null");
        }

        if (maps.isEmpty()) {
            System.out.println("empty");
        } else {
            System.out.println("not empty");
        }

        if (maps.get("hello").equals("")) {
            System.out.println("空");
        } else {
            System.out.println("非空");
        }

        if (maps.get("hello") != null) {
            System.out.println("不是null");
        } else {
            System.out.println("是null");
        }
    }
}
